package com.huanxing.cloud.product.controller.app;

import com.huanxing.cloud.common.core.util.Result;
import com.huanxing.cloud.common.security.annotation.HxInner;
import com.huanxing.cloud.product.api.dto.GoodsSkuStockReqDTO;
import com.huanxing.cloud.product.api.entity.GoodsSku;
import com.huanxing.cloud.product.api.entity.GoodsSkuSpecsValue;
import com.huanxing.cloud.product.service.IGoodsSkuService;
import com.huanxing.cloud.product.service.IGoodsSkuSpecsValueService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/sku")
@Tag(description = "app-sku", name = "商品sku-API")
public class AppGoodsSkuController {

	private final IGoodsSkuService goodsSkuService;

	private final IGoodsSkuSpecsValueService goodsSkuSpecsValueService;

	@HxInner
	@Operation(summary = "批量回滚库存")
	@PostMapping("/rollback")
	public Result<Void> rollbackStock(@RequestBody List<GoodsSkuStockReqDTO> goodsSkuStockRqDTOList) {
		goodsSkuService.rollbackStockList(goodsSkuStockRqDTOList);
		return Result.success();
	}

	@HxInner
	@Operation(summary = "批量查询sku")
	@GetMapping("/getBySkuIds")
	public Result<List<GoodsSku>> getBySkuIds(@RequestParam("ids") List<String> ids) {
		return Result.success(goodsSkuService.getListByIds(ids));
	}

	@HxInner
	@Operation(summary = "批量查询sku附带规格信息")
	@GetMapping("/getSkuByIds")
	public Result<List<GoodsSku>> getSkuByIds(@RequestParam("ids") List<String> ids) {
		return Result.success(goodsSkuService.getSkuByIds(ids));
	}

	@HxInner
	@Operation(summary = "扣减库存")
	@PostMapping("/reduce-stock")
	public Result<Boolean> updateSkuStock(@RequestBody List<GoodsSkuStockReqDTO> goodsSkuStockReqDTO) {
		return Result.success(goodsSkuService.reduceStock(goodsSkuStockReqDTO));
	}

	@Operation(summary = "通过skuId查询规格值")
	@GetMapping("/selectGoodsSkuSpecsValueList")
	public Result<List<GoodsSkuSpecsValue>> selectGoodsSkuSpecsValueList(@RequestParam("skuId") String skuId) {
		return Result.success(goodsSkuSpecsValueService.getBySkuId(skuId));
	}

	@HxInner
	@Operation(summary = "通过skuId查询")
	@GetMapping("/{skuId}")
	public Result<GoodsSku> getById(@PathVariable("skuId") String skuId) {
		return Result.success(goodsSkuService.getById(skuId));
	}

}
